<link rel="stylesheet" href="../assets/css/bootstrap.min.css"/>
<link rel="stylesheet" href="../assets/font-awesome/4.7.0/css/font-awesome.min.css"/>

<!-- page specific plugin styles -->
<link rel="stylesheet" href="../assets/css/sweetalert.css"/>
<!-- text fonts -->
<link rel="stylesheet" href="../assets/css/fonts.googleapis.com.css"/>
<link rel="stylesheet" href="../assets/css/style.css" />

<body style="background-color: #FFFFFF" onload="parent.scrollTo(0, 0);">
<div class="breadcrumbs ace-save-state" id="breadcrumbs">

</div>
<div class="page-content">
    <div class="row">
        <div class="col-xs-12">
            <!-- PAGE CONTENT BEGINS -->
            <form class="form-horizontal" id="settingForm" role="form">
                <div class="form-group" style="display: none">
                    <label class="col-sm-3 control-label no-padding-right"> 编号 </label>

                    <div class="col-sm-3">
                        <input type="text" id="settingId" name="id" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right"> 学生每月最大调课次数 </label>

                    <div class="col-sm-3">
                        <input type="text" id="studentmaxchangecourse" name="studentmaxchangecourse" class="form-control">
                    </div>
                </div>
                <div class="space-4"></div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right"> 教师每月最大调课次数 </label>

                    <div class="col-sm-3">
                        <input type="text" id="teachermaxchangecourse" name="teachermaxchangecourse" class="form-control">
                    </div>
                </div>
                <div class="space-4"></div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right"> 学生 —— 部门名 </label>

                    <div class="col-sm-3">
                        <input type="text" id="studentdepartmentname" name="studentdepartmentname" class="form-control">
                    </div>
                </div>
                <div class="space-4"></div>
                <div class="form-group">
                    <label class="col-sm-3 control-label no-padding-right"> 教师 —— 部门名 </label>
                    <div class="col-sm-3">
                        <input type="text" id="teacherdepartmentname" name="teacherdepartmentname" class="form-control">
                    </div>
                </div>
                <div class="space-4"></div>

                <div class="clearfix form-actions">
                    <div class="col-sm-offset-4 col-md-6">
                        <button class="btn btn-sm btn-info" type="button" onclick="saveSettings()">
                            <i class="ace-icon fa fa-check bigger-110"></i>
                            提交
                        </button>
                        &nbsp; &nbsp; &nbsp;
                        <button class="btn btn-default btn-sm" type="reset">
                            <i class="ace-icon fa fa-undo bigger-110"></i>
                            取消
                        </button>
                    </div>
                </div>
            </form>
        </div><!-- /.col -->
    </div>
</div>
</body>
<script src="../assets/js/jquery-2.1.4.min.js"></script>
<script src="../assets/js/bootstrap.min.js"></script>
<script src="../assets/js/sweetalert.min.js"></script>
<script type="text/javascript">
    $(function(){
        loadSettings();
    });
    function saveSettings() {
        $.ajax({
            url: '/setting/saveSettings',
            type: 'post',
            data: $("#settingForm").serialize(),
            dataType: 'json',
            success: function (result) {
                if (result.success) {
                    swal("Good Job", "修改成功", "success");
                    loadSettings();
                }else{
                    sweetAlert("Oops...", "修改失败", "error");
                }
            },
            error: function () {
                sweetAlert("Oops...", "加载失败", "error");
            }
        });
    }

    function loadSettings() {
        $.ajax({
            url: '/setting/getSettings',
            type: 'post',
            data: $("#settingForm").serialize(),
            dataType: 'json',
            success: function (result) {
                if (result.settings) {
                    var settings = result.settings;
                    $("#settingId").val(settings.id);
                    $("#studentmaxchangecourse").val(settings.studentmaxchangecourse);
                    $("#teachermaxchangecourse").val(settings.teachermaxchangecourse);
                    $("#studentdepartmentname").val(settings.studentdepartmentname);
                    $("#teacherdepartmentname").val(settings.teacherdepartmentname);
                }
            },
            error: function () {
                sweetAlert("Oops...", "加载失败", "error");
            }
        });
    }
</script>